#include <linux/kernel.h>
#include "nodelist.h"
#include "porting.h"

time_t jffs2_get_timestamp(void)
{
        struct timeval tv;
        (VOID)gettimeofday(&tv, NULL);
        return (unsigned int)(tv.tv_sec);
}

void jffs2_get_info_from_sb(void * data, struct jffs2_fs_info * info)
{
    struct jffs2_fs_info;
    struct super_block *jffs2_sb = (struct super_block *)NULL;
    struct jffs2_sb_info *c = (struct jffs2_sb_info *)NULL;

    jffs2_sb = (struct super_block *)(data);
    c = JFFS2_SB_INFO(jffs2_sb);

    info->sector_size = c->sector_size;
    info->nr_blocks = c->nr_blocks;
    info->free_size = c->free_size + c->dirty_size; //fixme need test!
}

static pthread_mutex_t jffs_mutex = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;

void jffsfs_Lock(void)
{
    (void)pthread_mutex_lock( &jffs_mutex);
}  /*lint !e454*/

void jffsfs_Unlock(void)
{
    (void)pthread_mutex_unlock(&jffs_mutex);/*lint !e455*/
}

void jffs_mutex_take(UINT32 *puwMuxHandle,UINT32 uwTimeout)
{
    UINT32 uwMuxHandle=*puwMuxHandle;
    (VOID)LOS_MuxPend(uwMuxHandle, uwTimeout);
}
void jffs_mutex_release(UINT32 *puwMuxHandle)
{
    UINT32 uwMuxHandle=*puwMuxHandle;
    (VOID)LOS_MuxPost(uwMuxHandle);
}
void jffs_mutex_create(UINT32 *puwMuxHandle)
{
    (VOID)LOS_MuxCreate(puwMuxHandle);
}
void jffs_mutex_delete(UINT32 *puwMuxHandle)
{
    UINT32 uwMuxHandle=*puwMuxHandle;
    (VOID)LOS_MuxDelete(uwMuxHandle);
}


void jffs_event_create(PEVENT_CB_S pstEventCB)
{

    (VOID)LOS_EventInit(pstEventCB);
}
void jffs_event_send(PEVENT_CB_S pstEventCB ,UINT32 uwEvents )
{

    (VOID)LOS_EventWrite(pstEventCB, uwEvents);
}
UINT32 jffs_event_recv(PEVENT_CB_S pstEventCB, UINT32 uwEventMask,UINT32 uwMode,UINT32 uwTimeOut)
{

    return(LOS_EventRead(pstEventCB, uwEventMask,uwMode,uwTimeOut));

}
void jffs_event_detach(PEVENT_CB_S pstEventCB )
{

    (VOID)LOS_EventWrite(pstEventCB, 0xFFFFFFFF);
}




